package my.ezbart;

import org.xmlvm.iphone.CGRect;
import org.xmlvm.iphone.CGSize;
import org.xmlvm.iphone.UIColor;
import org.xmlvm.iphone.UILabel;
import org.xmlvm.iphone.UIScreen;
import org.xmlvm.iphone.UIScrollView;
import org.xmlvm.iphone.UIView;
import org.xmlvm.iphone.UIViewController;

/**
 * @author Cecil Holmes
 * @version 0.1
 * 
 * ViewTrip.java 
 * 
 * View Controller responsible for displaying information regarding the available train routes. 
 * Train origin, destination, and time are received from the Trip Planner view.
 * 
 * Retrieves train information using the Train Retriever class and displays the retrieved trains using a Train View 
 * objects inside of a Scroll View.
 */
public class ViewTrip extends UIViewController {
    private UIView root = new UIView(UIScreen.mainScreen().getApplicationFrame());
    private UILabel origin = new UILabel(new CGRect(10, 10, UIScreen.mainScreen().getApplicationFrame().size.width-20, 20));
    private UILabel destination = new UILabel(new CGRect(10, 30, UIScreen.mainScreen().getApplicationFrame().size.width-20, 20));
    private UILabel time = new UILabel(new CGRect(10, 50, UIScreen.mainScreen().getApplicationFrame().size.width-20, 20));
    UIScrollView sv = new UIScrollView();
	private String[] tripData;

    public ViewTrip() {
        this.setTitle("View Trip");
        /*
         * The following statement associates an icon with the tab.
         * Ordinarily each tab would have an individual icon.
         */
        //this.getTabBarItem().setImage(UIImage.imageNamed("info.png"));
    }
    
    public ViewTrip(String[] data) {
    	this.setTitle("View Trip");
    	this.tripData = data; 
    }

    @Override
    public void loadView() {
    	//retrieves available trains based on input data
        TrainRetriever tr = new TrainRetriever(tripData);

        sv.setFrame(new CGRect(0, 90, UIScreen.mainScreen().getApplicationFrame().size.width, UIScreen.mainScreen().getBounds().size.height-110-90));
        sv.setContentSize(new CGSize(UIScreen.mainScreen().getApplicationFrame().size.width, 120*4));
        sv.setScrollEnabled(true);
        
        /* hard coded trains */
        for(int i=0; i<tr.getNumberOfTrains(); i++) {
        	sv.addSubview(tr.getTrainView(i));
        }
        
        origin.setText(this.tripData[0]);
        origin.setAdjustsFontSizeToFitWidth(true);
        destination.setText(this.tripData[1]);
        destination.setAdjustsFontSizeToFitWidth(true);
        time.setText(this.tripData[2]);
        time.setAdjustsFontSizeToFitWidth(true);
        
        origin.setBackgroundColor(UIColor.clearColor);
        destination.setBackgroundColor(UIColor.clearColor);
        time.setBackgroundColor(UIColor.clearColor);
        root.setBackgroundColor(UIColor.groupTableViewBackgroundColor);

        root.addSubview(sv);
        root.addSubview(origin);
        root.addSubview(destination);
        root.addSubview(time);
        
        this.setView(root);
    }
}